import 'package:favoritecate/core/model/meal_model.dart';
import 'package:favoritecate/core/services/meal_request.dart';
import 'package:favoritecate/core/viewmodel/filter_viewmodel.dart';
import 'package:flutter/material.dart';

class FYMealViewModel extends ChangeNotifier{
   List<FYMealModel> _meals = [];
   FYFilterViewModel _filter;

   List<FYMealModel> get meals{
     return _meals.where((meal){
       //过滤
        if(meal.isGlutenFree && !_filter.isGlutenfree){
          return false;
        }

        if(meal.isLactoseFree && !_filter.isLactorsefree){
          return false;
        }

        if(meal.isVegetarian && !_filter.isVegetarian){
          return false;
        }

        if(meal.isVegan && !_filter.isVegan){
          return false;
        }

        //满足条件
        return true;
     }).toList();
   }

   updateFilter(FYFilterViewModel filter){
     _filter = filter;
   }

   FYMealViewModel(){
     MealRequest.getMealData().then((res){
       _meals = res;
       //获取到数据发送通知
       notifyListeners();
     });
   }


}